home *** CD-ROM | disk | FTP | other *** search
- @echo off
- ! extractPath.bat Remove the a file or folder name from a full DOS path
- !
- ! extractPath path [varName]
- !
- ! where 'path' is the full path from which the item name is to be removed
- ! and 'varName' is a string containing the name of the global variable into
- ! which the resulting path is to be returned.
- !
- ! Note that no output variable is created if the parameter 'path' does not
- ! actually contain any path at all (ie. if it is the name of a local file or folder).
- ! Actually, the variable is removed if it already exists.
- !
- ! Copyright © 1994 by Rainbow Hill Pty Ltd. All rights reserved.
- !
-
- ! ensure that the first two parameters are there and that the third one is not
- set doserr=13
- if not "%3 " == " " goto ERR_LBL
- if "%1 " == " " goto ERR_LBL
- if "%2 " == " " goto ERR_LBL
-
- ! extract the name from the full path
- set extractPath_name=%1
- onerror SKIP_LBL
- sstr/e/r extractPath_name "\"
- :SKIP_LBL
- onerror SKIP2_LBL
- sstr/e/r extractPath_name ":"
- :SKIP2_LBL
-
- ! check whether there is a path
- if not "%extractPath_name%" == "%1" goto THERE_IS_LBL
- set %2=
- set doserr=0
- goto DONE_LBL
-
- :THERE_IS_LBL
- ! copy the full path to a temporary variable and remove from it the name
- set extractPath_path=%1
- decr extractPath_path by "%extractPath_name%"
- set %2=%extractPath_path%
- set doserr=0
- goto DONE_LBL
-
- :ERR_LBL
- show %doserr%
-
- :DONE_LBL
- ! remove the temporary variables
- set extractPath_name=
- set extractPath_path=
-